package com.wyj.log

import com.elvishew.xlog.printer.file.naming.FileNameGenerator
import java.text.SimpleDateFormat
import java.util.*

/**
 * Generate file name according to the timestamp, different dates will lead to different file names.
 */
class TagDateFileNameGenerator(private val tag: String) : FileNameGenerator {
    var mLocalDateFormat: ThreadLocal<SimpleDateFormat> = object : ThreadLocal<SimpleDateFormat>() {
        override fun initialValue(): SimpleDateFormat {
            return SimpleDateFormat("yyyy-MM-dd", Locale.US)
        }
    }

    override fun isFileNameChangeable(): Boolean {
        return true
    }

    /**
     * Generate a file name which represent a specific date.
     */
    override fun generateFileName(logLevel: Int, timestamp: Long): String {
        val sdf = mLocalDateFormat.get()
        sdf.timeZone = TimeZone.getDefault()
        return "${tag}-${sdf.format(Date(timestamp))}"
    }
}
